home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-02-13 | 11.4 KB | 498 lines | [TEXT/MPS ] |
- // UEenie.cp --------------------------------------------------------------------------
- // Copyright © 1991 by Apple Computer, Inc. All rights reserved.
-
-
- // INCLUDES ---------------------------------------------------------------------------
-
- #include "EenieRez.h" // combined header file for resource IDs
- #include "UEenie.h" // class definitions
-
-
- // CLASS METHODS ----------------------------------------------------------------------
-
- // TAdornerApplication ----------------------------------------------------------------
-
- #undef Inherited
- #define Inherited TApplication
-
- #pragma segment AInit
- DefineClass(TAdornerApplication, Inherited);
-
- void TAdornerApplication::IAdornerApplication(OSType fileType, OSType creator)
- {
- Inherited::IApplication(fileType, creator);
-
- // so the linker doesn't dead strip class info
- macroDontDeadStrip(TEenieView1);
- macroDontDeadStrip(TEenieView2);
- macroDontDeadStrip(TEenieView3);
- macroDontDeadStrip(TEenieView4);
- macroDontDeadStrip(TGrayFill);
- macroDontDeadStrip(TOtherGrayFill);
- macroDontDeadStrip(TEtchedFrame);
-
- RegisterStdType("TGrayFill", 'gray'); // register adorner types
- RegisterStdType("TOtherGrayFill", 'dgry');
- RegisterStdType("TEtchedFrame", 'etch');
- }
-
-
- #pragma segment AOpen
- TDocument* TAdornerApplication::DoMakeDocument(CommandNumber /* itsCmdNumber */,
- TFile* /* itsFile */)
- {
- FailInfo fi;
- TAdornerDocument* anAdornerDocument;
-
- Try(fi) {
- anAdornerDocument = new TAdornerDocument;
- anAdornerDocument->IAdornerDocument();
- fi.Success();
- }
- else
- fi.ReSignal();
-
- return anAdornerDocument;
-
- }
-
-
- // TAdornerDocument Methods -----------------------------------------------------------
-
- #undef Inherited
- #define Inherited TDocument
-
- #pragma segment AInit
- DefineClass(TAdornerDocument, Inherited);
-
-
- void TAdornerDocument::IAdornerDocument()
- {
- Inherited::IDocument();
- }
-
-
- #pragma segment AOpen
- void TAdornerDocument::DoMakeViews(Boolean /*forPrinting*/)
- {
- TWindow* aWindow = NULL;
- TEenieView1* view1 = NULL;
- TEenieView2* view2 = NULL;
- TEenieView3* view3 = NULL;
- TEenieView4* view4 = NULL;
-
- FailInfo fi;
-
- Try(fi) {
- // create Window
- aWindow = gViewServer->NewTemplateWindow(1002, this);
-
- // add window adorner
- aWindow->AddAdorner(NewStdAdorner('dgry',"",'dgry', kFreeOnDeletion),
- kAdornLast, kRedraw);
-
- // create views
- view1 =(TEenieView1 *) aWindow->FindSubView('VW01'); FailNIL(view1);
- view2 =(TEenieView2 *) aWindow->FindSubView('VW02'); FailNIL(view2);
- view3 =(TEenieView3 *) aWindow->FindSubView('VW03'); FailNIL(view3);
- view4 =(TEenieView4 *) aWindow->FindSubView('VW04'); FailNIL(view4);
-
- // add adorners to the new views
- view1->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion),
- kAdornFirst, kRedraw);
- view2->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion),
- kAdornFirst, kRedraw);
- view3->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion),
- kAdornFirst, kRedraw);
- view4->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion),
- kAdornFirst, kRedraw);
-
- // create dependencies
- view1->AddDependent(view4); view2->AddDependent(view3);
- view3->AddDependent(view2); view4->AddDependent(view1);
-
- fi.Success();
- }
- else
- fi.ReSignal();
- }
-
-
- // TEenieView ----------------------------------------------------------------
-
- #undef Inherited
- #define Inherited TView
-
- #pragma segment AInit
- DefineClass(TEenieView, Inherited);
-
- TEenieView::TEenieView()
- {
-
- }
-
-
- #pragma segment ARes
- void TEenieView::DoPostCreate(TDocument* itsDocument)
- {
- Inherited::DoPostCreate(itsDocument);
- this->fCounter = 0L; // zero counter
- this->AddAdorner(NewStdAdorner('etch',"",'etch', kFreeOnDeletion),
- kAdornFirst, kRedraw);
- }
-
-
- #pragma segment Main
- void TEenieView::Hilite()
- {
- CRect tempRect;
-
- this->GetQDExtent(tempRect); // get the area
- LMSetHiliteMode(pHiliteBit); // clear bit for selection color
- HiliteColor(gDKPink); // switch temp to new hilite color
- InvertRect(tempRect); // invert the area
- }
-
-
- // TEenieView SubViews ----------------------------------------------------------
-
- #undef Inherited
- #define Inherited TEenieView
-
- #pragma segment ARes
- DefineClass(TEenieView1, Inherited);
-
- void TEenieView1::Draw(const VRect& area)
- {
- Inherited::Draw(area);
- this->DrawNumber();
- }
-
-
- #pragma segment ARes
- void TEenieView1::DrawNumber()
- {
- CStr255 first = "Moo view clicked";
- CStr255 count;
- CStr255 second = "times...";
-
- PenNormal();
-
- TextFont(times); TextSize(14); MoveTo(10,15);
- DrawString(first);
-
- TextSize(48); MoveTo(40,90);
- NumToString(this->fCounter, count);
- DrawString(count);
-
- TextSize(14); MoveTo(10,140);
- DrawString(second);
- }
-
- #pragma segment Main
- void TEenieView1::DoMouseCommand(VPoint& /*theMouse*/,
- TToolboxEvent* /*event*/,
- CPoint /*hysteresis*/)
- {
- this->Hilite(); // flash for the user for mouse click
- this->Changed(eVIEW1,this); // send change directive to dependent view
- }
-
- #pragma segment ARes
- void TEenieView1::DoUpdate(ChangeID theID,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)
- {
- if (theID == eVIEW4){
- this->fCounter = this->fCounter + 1L; // increment counter
- this->ForceRedraw(); // update the screen
- }
- }
-
- // --------------------------
-
- #undef Inherited
- #define Inherited TEenieView
-
- #pragma segment ARes
- DefineClass(TEenieView2, Inherited);
-
- void TEenieView2::Draw(const VRect& area)
- {
- Inherited::Draw(area);
- this->DrawNumber();
- }
-
-
- #pragma segment ARes
- void TEenieView2::DrawNumber()
- {
- CStr255 first = "Minee view clicked";
- CStr255 count;
- CStr255 second = "times...";
-
- PenNormal();
-
- TextFont(times); TextSize(14); MoveTo(10,15);
- DrawString(first);
-
- TextSize(48); MoveTo(40,90);
- NumToString(this->fCounter, count);
- DrawString(count);
-
- TextSize(14); MoveTo(10,140);
- DrawString(second);
- }
-
-
- #pragma segment Main
- void TEenieView2::DoMouseCommand(VPoint& /*theMouse*/,
- TToolboxEvent* /*event*/,
- CPoint /*hysteresis*/)
- {
- this->Hilite(); // flash for the user for mouse click
- this->Changed(eVIEW2,this); // send change directive to dependent view
- }
-
-
- #pragma segment ARes
- void TEenieView2::DoUpdate(ChangeID theID,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)
- {
- if (theID == eVIEW3) {
- this->fCounter = this->fCounter + 1L; // increment counter
- this->ForceRedraw(); // update the screen
- }
- }
-
-
- // --------------------------
-
- #undef Inherited
- #define Inherited TEenieView
-
- #pragma segment ARes
- DefineClass(TEenieView3, Inherited);
-
- void TEenieView3::Draw(const VRect& area)
- {
- Inherited::Draw(area);
- this->DrawNumber();
- }
-
-
- #pragma segment ARes
- void TEenieView3::DrawNumber()
- {
- CStr255 first = "Meenie view clicked";
- CStr255 count;
- CStr255 second = "times...";
-
- PenNormal();
-
- TextFont(times); TextSize(14); MoveTo(10,15);
- DrawString(first);
-
- TextSize(48); MoveTo(40,90);
- NumToString(this->fCounter, count);
- DrawString(count);
-
- TextSize(14); MoveTo(10,140);
- DrawString(second);
- }
-
-
- #pragma segment Main
- void TEenieView3::DoMouseCommand(VPoint& /*theMouse*/,
- TToolboxEvent* /*event*/,
- CPoint /*hysteresis*/)
- {
- this->Hilite(); // flash for the user for mouse click
- this->Changed(eVIEW3,this); // send change directive to dependent view
- }
-
-
- #pragma segment ARes
- void TEenieView3::DoUpdate(ChangeID theID,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)
- {
- if (theID == eVIEW2) {
- this->fCounter = this->fCounter + 1L; // increment counter
- this->ForceRedraw(); // update the screen
- }
- }
-
-
- // --------------------------
- #undef Inherited
- #define Inherited TEenieView
-
- #pragma segment ARes
- DefineClass(TEenieView4, Inherited);
-
- void TEenieView4::Draw(const VRect& area)
- {
- Inherited::Draw(area);
- this->DrawNumber();
- }
-
- #pragma segment ARes
- void TEenieView4::DrawNumber() // draw information in view
- {
- CStr255 first = "Eenie view clicked";
- CStr255 count;
- CStr255 second = "times...";
-
- PenNormal();
-
- TextFont(times); TextSize(14); MoveTo(10,15);
- DrawString(first);
-
- TextSize(48); MoveTo(40,90);
- NumToString(this->fCounter, count);
- DrawString(count);
-
- TextSize(14); MoveTo(10,140);
- DrawString(second);
- }
-
-
- #pragma segment Main
- void TEenieView4::DoMouseCommand(VPoint& /*theMouse*/,
- TToolboxEvent* /*event*/,
- CPoint /*hysteresis*/)
- {
- this->Hilite(); // flash for the user for mouse click
- this->Changed(eVIEW4,this); // send change directive to dependent view
- }
-
- #pragma segment ARes
- void TEenieView4::DoUpdate(ChangeID theID,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)
- {
- if (theID == eVIEW1){
- this->fCounter = this->fCounter + 1L; // increment counter
- this->ForceRedraw(); // update the screen
- }
- }
-
-
- // TAdorners ------------------------------------------------------------------
-
- #undef Inherited
- #define Inherited TAdorner
-
- #pragma segment ARes
- DefineClass(TGrayFill, Inherited);
-
- void TGrayFill::Draw(TView* itsView, const VRect& /*area*/)
- {
- CRGBColor saveColor;
- PenState savePenState;
- VRect adornArea;
- CRect QDArea;
- CRect tempRect;
-
- GetPenState(&savePenState); // save off the current pen state
- GetIfColor(saveColor); // and the foreground color
- PenNormal();
-
- itsView->GetAdornExtent(adornArea); // get area
- itsView->ViewToQDRect(adornArea, QDArea);
- tempRect = QDArea;
-
- SetIfColor(gRGBGray); // colorize it
- PaintRect(tempRect);
-
- SetIfColor(saveColor); // restore the foreground color and the pen
- SetPenState(&savePenState);
- }
-
-
-
- #undef Inherited
- #define Inherited TAdorner
-
- #pragma segment ARes
- DefineClass(TOtherGrayFill, Inherited);
-
- void TOtherGrayFill::Draw(TView* itsView, const VRect& /*area*/)
- {
- CRGBColor saveColor;
- PenState savePenState;
- VRect adornArea;
- CRect QDArea;
- CRect tempRect;
-
- GetPenState(&savePenState); // save off the current pen state
- GetIfColor(saveColor); // and the foreground color
- PenNormal();
-
- itsView->GetAdornExtent(adornArea); // get area
- itsView->ViewToQDRect(adornArea, QDArea);
- tempRect = QDArea;
-
- SetIfColor(gDKGray); // dark gray scale, grey for you English
- PaintRect(tempRect);
-
- SetIfColor(saveColor); // Restore the foreground color and the pen
- SetPenState(&savePenState);
- }
-
-
- #undef Inherited
- #define Inherited TAdorner
-
- #pragma segment ARes
- DefineClass(TEtchedFrame, Inherited);
-
- TEtchedFrame::TEtchedFrame()
- {
-
- fInset.h = 1;
- fInset.v = 1;
- }
-
-
- #pragma segment ARes
- void TEtchedFrame::Draw(TView* itsView, const VRect& /*area*/)
- {
- CRGBColor saveColor;
- PenState savePenState;
- VRect adornArea;
- CRect QDArea;
- CRect tempRect;
-
- GetPenState(&savePenState); // Save off the current pen state
- GetIfColor(saveColor); // and the foreground color
- PenNormal();
-
- itsView->GetAdornExtent(adornArea); // get area
- itsView->ViewToQDRect(adornArea, QDArea);
- tempRect = QDArea;
-
- SetIfColor(gRGBBlack);
- InsetRect(tempRect, fInset.h, fInset.v);
- FrameRect(tempRect); // Frame the shadows
-
- OffsetRect(tempRect, 1, 1);
- SetIfColor(gRGBWhite);
- FrameRect(tempRect); // Frame the light edges
-
- OffsetRect(tempRect, -1, -1);
- SetCPixel(tempRect.left, tempRect.bottom, gRGBBlack); // Finish the corners
- SetCPixel(tempRect.right, tempRect.top, gRGBBlack);
-
- SetIfColor(saveColor); // Restore the foreground color and the pen
- SetPenState(&savePenState);
- }
-
-
-